package com.zhentao.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhentao.dto.system.SysRoleDto;
import com.zhentao.entity.system.SysRole;
import com.zhentao.service.SysRoleService;
import com.zhentao.vo.common.Result;
import com.zhentao.vo.common.ResultCodeEnum;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping(value = "/admin/system/sysRole")
public class SysRoleController {

    @Resource
    private SysRoleService sysRoleService ;

    /**
     * 角色列表加分页
     * @param sysRoleDto
     * @return
     */
    @PostMapping("/findByPage")
    public Result<Page<SysRole>> findByPage(@RequestBody SysRoleDto sysRoleDto) {
        Page<SysRole> pageInfo = sysRoleService.findByPage(sysRoleDto) ;
        return Result.build(pageInfo , ResultCodeEnum.SUCCESS) ;
    }

    /**
     * 新增角色
     * @param SysRole
     * @return
     */
    @PostMapping("/saveSysRole")
    public Result saveSysRole(@RequestBody SysRole SysRole) {
        sysRoleService.saveSysRole(SysRole) ;
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }

    /**
     * 修改角色
     * @param sysRole
     * @return
     */
    @PutMapping("/updateSysRole")
    public Result updateSysRole(@RequestBody SysRole sysRole) {
        sysRoleService.updateSysRole(sysRole) ;
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }

    /**
     * 删除角色
     * @param roleId
     * @return
     */
    @DeleteMapping(value = "/deleteById/{roleId}")
    public Result deleteById(@PathVariable(value = "roleId") Long roleId) {
        sysRoleService.deleteById(roleId) ;
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }

    /**
     * 查询所有的角色
     * @return
     */
    @GetMapping("/findAllRoles/{userId}")
    public Result<Map<String , Object>> findAllRoles(@PathVariable(value = "userId") Long userId) {
        Map<String, Object> resultMap = sysRoleService.findAllRoles(userId);
        return Result.build(resultMap , ResultCodeEnum.SUCCESS)  ;
    }
}